$('document').ready(function() {

    var $container = $(".description");
    var $close = $("#close");
    //Digit only
    $(".digits").keydown(function(event) {
        // Allow: backspace, delete, tab, escape, and enter
        if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 ||
            // Allow: Ctrl+A
            (event.keyCode == 65 && event.ctrlKey === true) ||
            // Allow: home, end, left, right
            (event.keyCode >= 35 && event.keyCode <= 39)) {
            // let it happen, don't do anything
            return;
        }
        else {
            // Ensure that it is a number and stop the keypress
            if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
                event.preventDefault();
            }
        }
    });
    $close.bind('click', function() {
        $container.fadeOut(1000, function() {
            $container.css('display', 'none');
        });
    });

    $("#submit_btn").bind("click", function() {
        var $password = $('#password');
        var $repeat_password = $('#repeat_password');
        if ($password.val() != $repeat_password.val()) {
            $('#text_content').html("Пароли не совпадают. Поторите ввод.");
            $container.fadeIn(1000);
            return false;
        } else if (isValidEmailAddress($('#email').val()) != true) {
            $('#text_content').html("Введите корректый e-mail адрес!");
            $container.fadeIn(1000);
            return false;

        } else if ($password.val() == "" || $repeat_password.val() == "") {
            $('#text_content').html("Пароль не может быть пустым");
            $container.fadeIn(1000);
            return false;
        } else {
            return true;
        }

        function isValidEmailAddress(emailAddress) {
            var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
            return pattern.test(emailAddress);
        }

    });

});